<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org">
<head>
	<meta charset="UTF-8">
	<title>品牌列表</title>
	<script th:src="@{/layui/layui.js}" type="text/javascript"></script>
	<link th:href="@{/layui/css/layui.css}" rel="stylesheet" />
	</head>
	
	<body>
		
			<div class="layui-panel" style="padding: 8px;">
	    <fieldset class="layui-elem-field layui-border-blue">
	        <legend>搜索信息</legend>
	        <form class="layui-form layui-form-pane" style="margin: 20px;">
	            <div class="layui-form-item">
	                <div class="layui-inline">
	                    <label class="layui-form-label">品牌名称</label>
	                    <div class="layui-input-inline">
	                        <input class="layui-input" type="text" name="name" autocomplete="off" />
	                    </div>
	                </div>
	                <div class="layui-inline">
	                    <div class="layui-input-inline">
	                        <a id="searchBtn" class="layui-btn layui-btn-primary" lay-submit="" lay-filter="searchBtn">
	                            <i class="layui-icon layui-icon-search"></i>
	                            搜索
	                        </a>
	                    </div>
	                </div>

	            </div>
	        </form>
	    </fieldset>
	    <div>
	        <table id="brandListTable" lay-filter="brandListTable"></table>
	    </div>
	</div>
		<!---->
	<script id="tool" type="text/html">
		<a class="layui-btn layui-btn-warm layui-btn-xs" lay-event="edit">编辑</a>
		<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="delete">删除</a>
	</script>
	<!---->
	<script id="tableBar" type="text/html">
	    <a class="layui-btn layui-btn-normal layui-btn-md" lay-event="add">
	        <i class="layui-icon layui-icon-add-1"></i>
	        新增
	    </a>
	    <a class="layui-btn layui-btn-danger layui-btn-md" lay-event="delete">
	        <i class="layui-icon layui-icon-delete"></i>
	        删除
	    </a>
	</script>
	<!---->
	<script id="picUrl" type="text/html">
		<img src="/file/fc/showImg/{{d.picUrl}}" style="border-radius: 25px;width: 25px;height: 25px">
	</script>
	
<script>
	var $,active;
		layui.use(['table','form','laydate','layer','dropdown','jquery'],function(){
			
        	var table = layui.table,form = layui.form,layer = layui.layer,
            	laydate = layui.laydate,dropdown = layui.dropdown;
        		$ = layui.jquery;
            	
			laydate.render({
				elem:'#endDate'
			})
			laydate.render({
				elem:'#endDate'
			})


			//
			/*$('body').keydown(function (){
				if(event.keyCode == 13){
					$('#searchBtn').click();
				}
			});*/
			
			//加载动态表格
			table.render({
				
				elem:'#brandListTable',
				height:'full-160',
				page:true,
				toolbar:'#tableBar',
				url:'/brand/bc/find',
				cols:[
						[
					{type:'numbers',fixed:'left'},
					{type:'checkbox',fixed:'left'},
					{field:'brandSn',title:'品牌商编号',width:150,align: 'center'},
					{field:'name',title:'品牌名称',width:180,align: 'center'},
					{field:'picUrl',title:'品牌商图片',width:100,align: 'center',templet:'#picUrl'},
					{field:'detail',title:'品牌介绍',align: 'center'},
					{field:'floorPrice',title:'底价(/￥)',width:100,align: 'center'},
					{fixed:'right',title:'操作',width:150,align:'center',toolbar:'#tool'},
				]
				],
				
			});

			//搜索
			form.on('submit(searchBtn)',function (data) {
				var dataForm = data.field;
				table.reload('brandListTable',{
					page:{
						curr:1
					},
					where:{
						name:dataForm.name
					}
				})
			});

			//
			active = {
				addOrUpdate:function (title,btn,content) {
					var b = false;
					top.layer.open({
						title:title,
						type:2,
						content:content,
						area:['900px','750px'],
						btn:[btn,'取消关闭'],
						btn1:function (i,o) {
							b = true;
							o.find('iframe')[0].contentWindow.btnSubmit();
						},
						end:function (i,o) {
							if (b) layui.table.reload('brandListTable');
						}
					})
				},
				deleteConfirm:function (ids) {

					layer.confirm('确定删除'+(ids.length==1?'该记录':'这些记录')+'吗？',function (index) {
						//console.log(ids);
						if (index>0){
							$.ajax({
								type:'post',
								url:'/brand/bc/batchUpdate',
								data:{
									ids:ids
								},
								dataType:'json',
								success:function (result) {
									layer.msg(result.msg);
									if (result.is){
										layui.table.reload('brandListTable');
									}
								}
							})
						}
						layer.close(index);
					});

				}
			}

			//add
			table.on('toolbar(brandListTable)',function (obj) {
				var event = obj.event;
				if ("add"==event){
					active.addOrUpdate('新增品牌商','确认添加','/page/mallManagement/brandAdd');
				}
				else if ('delete' == event){
					var checkStatus = table.checkStatus(obj.config.id);

					if (checkStatus.data.length>0){
						var ids = [];
						$.each(checkStatus.data,function (i,cs) {
							ids.push(cs.id);
						});

						active.deleteConfirm(ids);
					}else {
						layer.msg("请选择要删除的记录！");
					}


				}
			});

			table.on('tool(brandListTable)',function (obj) {
				var event = obj.event;

				if ("edit" == event){
					active.addOrUpdate('更新商品','保存更新','/page/mallManagement/brandEdit/'+obj.data.id);
				}
				else if ('delete' == event){
					var ids = [];
					ids.push(obj.data.id);
					active.deleteConfirm(ids);
				}


			})
			
		});
	
</script>
	
	
	</body>
</html>
